from __future__ import print_function

import abc

__all__ = [
    'GenerateName',
    'GenerateNameU',
    'CClientViewport',
    ]

# Used to store prefixes for previously generated names
GNameGenInfo = {}

def GenerateName(prefix):
    '''
    Generates a name by appending a number to a prefix. Used to generate
    actor names using their class name. String version.
    '''
    if isinstance(prefix, unicode):
        prefix = prefix.encode('utf-8')
    num = 0
    try:
        num = GNameGenInfo[prefix]
    except KeyError:
        pass
    num += 1
    GNameGenInfo[prefix] = num
    return ''.join((prefix, '_', unicode(num)))

def GenerateNameU(prefix):
    '''
    Generates a name by appending a number to a prefix. Used to generate
    actor names using their class name. Unicode version.
    '''
    if isinstance(prefix, str):
        prefix = unicode(prefix)
    num = 0
    try:
        num = GNameGenInfo[prefix]
    except KeyError:
        pass
    num += 1
    GNameGenInfo[prefix] = num
    return u''.join((prefix, u'_', unicode(num)))

def SimulatedNoOp(*args, **kwds):
    pass
    
class CClientViewport(object):
    '''Abstract base class for client viewports.
    
    This class provides an interface for CClient to retrieve the platform-
    specific window handle in order to establish an OpenGL context.
    
    A derived instance of this class with a valid window handle is
    required to initialize the client.
    '''
    __metaclass__ = abc.ABCMeta
    
    @abc.abstractmethod
    def GetWindowHandle(self):
        '''Retrieve window handle as int.'''
    
    @abc.abstractmethod
    def CheckWindowHandle(self):
        '''Check if a window handle is still valid.'''
    
    @abc.abstractmethod
    def GetSize(self):
        '''
        Return the size of the viewport in pixels.
        
        Return value must be convertible to FRectI.
        '''
        
    @abc.abstractmethod
    def OnClientInited(self, client):
        pass
        
    @abc.abstractmethod
    def OnClientExiting(self):
        pass
        
    